#include "recource.h"
#include "mainwindow.h"
#include "scene/mainscene.h"
#include "scene/settingscene.h"
#include "scene/helpscene.h"
#include "view/promptview.h"
#include <QImage>
#include "scene/selscene.h"
#include "scene/gamescene.h"
#include <QPixmap>
#include "item/imageitem.h"
#include <QSettings>
#include "sound/GameSounds.h"

MainWindow* Recource::m_mainwindow = NULL;
MainScene*  Recource::m_mainscene = NULL;
SettingScene*   Recource::m_setscene = NULL;
HelpScene*  Recource::m_helpscene = NULL;
QImage*     Recource::m_promptbgImage = new QImage();
QImage*     Recource::m_promptYesImage = new QImage();
QImage*     Recource::m_promptYesEnImage = new QImage();
QImage*     Recource::m_promptNoImage = new QImage();
QImage*     Recource::m_promptNoEnImage = new QImage();
QImage*     Recource::m_promptmbgImage_new=new QImage();
QImage*     Recource::m_promptmbgImage_new_cn=new QImage();
SelScene*     Recource::m_selscene = NULL;
GameScene*  Recource::m_gamescene = NULL;
QImage*     Recource::m_pauseBackImage = new QImage();
QImage*     Recource::m_pauseBackHkImage = new QImage();
QImage*     Recource::m_pauseBackEnImage = new QImage();
QImage*     Recource::m_pauseContiueImage = new QImage();
QImage*     Recource::m_pauseContiueHkImage = new QImage();
QImage*     Recource::m_pauseContiueEnImage = new QImage();
QImage*     Recource::m_pauseRestartImage = new QImage();
QImage*     Recource::m_pauseRestartHkImage = new QImage();
QImage*     Recource::m_pauseRestartEnImage = new QImage();
QImage*     Recource::m_pausebgImage = new QImage();
QImage*     Recource::m_pausebgHkImage = new QImage();
QImage*     Recource::m_pausebgEnImage = new QImage();
QPixmap*    Recource::m_steelballImage = NULL;
QImage*     Recource::m_backbtnImage = new QImage();
QImage*     Recource::m_backbtnEnImage = new QImage();
QImage*     Recource::m_soundOpenImage = new QImage();
QImage*     Recource::m_soundCloseImage = new QImage();
QImage*     Recource::m_mainBgCnImage = new QImage();
QImage*     Recource::m_mainBgEnImage = new QImage();
QImage*     Recource::m_mainBgHkImage = new QImage();
QImage*     Recource::m_mainExitCnImage = new QImage();
QImage*     Recource::m_mainExitEnImage = new QImage();
QImage*     Recource::m_mainPlayCnImage = new QImage();
QImage*     Recource::m_mainPlayEnImage = new QImage();
QImage*     Recource::m_mainPlayHkImage = new QImage();
QImage*     Recource::m_promptmbgImage = new QImage();
QImage*     Recource::m_promptmbgHkImage = new QImage();
QImage*     Recource::m_promptmbgEnImage = new QImage();
QPixmap*    Recource::m_gamebg1arr[3] = {NULL,NULL,NULL};
QPixmap*    Recource::m_gamescore = NULL;
QPixmap*    Recource::m_gamescore1 = NULL;
int         Recource::m_ilevelScore_1 = -1;
int         Recource::m_ilevelScore_2 = -1;
int         Recource::m_ilevelScore_3 = -1;
QImage*     Recource::m_SelLevel2BtnImage = new QImage();
QImage*     Recource::m_SelLevel2BtnPImage = new QImage();
QImage*     Recource::m_SelLevel3BtnImage = new QImage();
QImage*     Recource::m_SelLevel3BtnPImage = new QImage();
QImage*     Recource::m_SelBgCnImage = new QImage();
QImage*     Recource::m_SelBgEnImage = new QImage();
GameSounds* Recource::m_gamesound = NULL;
bool        Recource::m_bPlaySound = false;
QImage*     Recource::m_overBgImage = new QImage();
QImage*     Recource::m_overBgHkImage = new QImage();
QImage*     Recource::m_overBgEnImage = new QImage();
int         Recource::m_iLanguage = 0;
QImage*     Recource::m_continueCnBtnImage = new QImage();
QImage*     Recource::m_continueHKBtnImage = new QImage();
QImage*     Recource::m_continueEnBtnImage = new QImage();
QImage*     Recource::m_continueCnMbgImage = new QImage();
QImage*     Recource::m_continueHKMbgImage = new QImage();
QImage*     Recource::m_continueEnMbgImage = new QImage();
QImage*     Recource::m_helpBgCnImage = new QImage();
QImage*     Recource::m_helpBgEnImage = new QImage();
QImage*     Recource::m_helpBgHkImage = new QImage();
QImage*     Recource::m_aboutBgCnImage = new QImage();
QImage*     Recource::m_aboutBgEnImage = new QImage();
QImage*     Recource::m_aboutBgHkImage = new QImage();


Recource::Recource()
{

}

void Recource::SetMain()
{
    Recource::m_gamesound->stop(1);
    Recource::m_gamesound->stop(0);
    if(Recource::m_bPlaySound)
    {
        Recource::m_gamesound->playBgSound(0);
    }

    m_mainwindow->setScene(m_mainscene);
}

void Recource::SetSet()
{
    m_mainwindow->setScene(m_setscene);
}

void Recource::SetHelp()
{
    m_mainwindow->setScene(m_helpscene);
}

void Recource::LoadImage()
{
    Recource::m_promptbgImage->load(":/image/prompt/hint1.png");
    Recource::m_promptYesImage->load(":/image/prompt/A_0111.png");
    Recource::m_promptYesEnImage->load(":/image/prompt/yes_en57,360.png");
    Recource::m_promptNoImage->load(":/image/prompt/A_0222.png");
    Recource::m_promptNoEnImage->load(":/image/prompt/no_en213,360.png");
    Recource::m_promptmbgImage->load(":/image/prompt/tip_over.jpg");
    Recource::m_promptmbgHkImage->load(":/image/prompt/tip_exit_f.jpg");
    Recource::m_promptmbgEnImage->load(":/image/prompt/tip_exit_en.jpg");
    Recource::m_promptmbgImage_new->load(":/image/prompt/tip_new.png");
    Recource::m_promptmbgImage_new_cn->load(":/image/prompt/tip_new_cn.png");

    Recource::m_pausebgImage->load(":/image/pause/Prompt_bg.png");
    Recource::m_pausebgHkImage->load(":/image/pause/tip_pause_f.jpg");
    Recource::m_pausebgEnImage->load(":/image/pause/tip_pause_en.jpg");
    Recource::m_pauseContiueImage->load(":/image/pause/122.png");
    Recource::m_pauseContiueHkImage->load(":/image/pause/tip_conture_f.png");
    Recource::m_pauseContiueEnImage->load(":/image/pause/tip_continue_en65,206.png");
    Recource::m_pauseRestartImage->load(":/image/pause/324.png");
    Recource::m_pauseRestartHkImage->load(":/image/pause/tip_replay_f.png");
    Recource::m_pauseRestartEnImage->load(":/image/pause/tip_replay_en.png");
    Recource::m_pauseBackImage->load(":/image/pause/3244.png");
    Recource::m_pauseBackHkImage->load(":/image/pause/tip_menu_f.png");
    Recource::m_pauseBackEnImage->load(":/image/pause/tip_menu_en.png");

    m_steelballImage = new QPixmap();
    m_steelballImage->load(":/image/game/ball.png");

    m_backbtnImage->load(":/image/level_back.png");
    m_backbtnEnImage->load(":/image/level_back_en.png");

    m_soundOpenImage->load(":/image/main/music_on.png");
    m_soundCloseImage->load(":/image/main/music_off.png");
    m_mainBgCnImage->load(":/image/main/camerabg.jpg");
    m_mainBgEnImage->load(":/image/main/s_bg_en.jpg");
    m_mainBgHkImage->load(":/image/main/s_bg_f.jpg");
    m_mainExitCnImage->load(":/image/main/exit.png");
    m_mainExitEnImage->load(":/image/main/exit_en.png");
    m_mainPlayCnImage->load(":/image/main/play.png");
    m_mainPlayHkImage->load(":/image/main/play_f.jpg");
    m_mainPlayEnImage->load(":/image/main/play_en.png");

    QString str;
    for(int i = 0; i < 3; ++i)
    {
        m_gamebg1arr[i] = new QPixmap();
        str = QString(":/image/game/game_level%1.jpg").arg(i + 1);
        m_gamebg1arr[i]->load(str);
    }
    m_gamescore = new QPixmap();
    m_gamescore->load(":/image/game/font.png");
    m_gamescore1 = new QPixmap();
    m_gamescore1->load(":/image/game/font1.png");

    m_SelLevel2BtnImage->load(":/image/sel/level2_n.jpg");
    m_SelLevel2BtnPImage->load(":/image/sel/level2_P.jpg");
    m_SelLevel3BtnImage->load(":/image/sel/level3_n.jpg");
    m_SelLevel3BtnPImage->load(":/image/sel/level3_p.jpg");
    m_SelBgCnImage->load(":/image/sel/level_bg.jpg");
    m_SelBgEnImage->load(":/image/sel/level_en.jpg");

    m_overBgImage->load(":/image/over/tip_over.png");
    m_overBgHkImage->load(":/image/over/tip_over_f.jpg");
    m_overBgEnImage->load(":/image/over/tip_over_en.jpg");

    m_continueCnBtnImage->load(":/image/continue/ok_cn137,360.png");
    m_continueHKBtnImage->load(":/image/continue/ok_fcn.png");
    m_continueEnBtnImage->load(":/image/continue/ok_en.png");
    m_continueCnMbgImage->load(":/image/continue/tip_new_cn.jpg");
    m_continueHKMbgImage->load(":/image/continue/tip_exit_cn.jpg");
    m_continueEnMbgImage->load(":/image/continue/tip_new_en.jpg");

    m_helpBgCnImage->load(":/image/help/help.jpg");
    m_helpBgHkImage->load(":/image/help/help_f.jpg");
    m_helpBgEnImage->load(":/image/help/help_en.jpg");

    m_aboutBgCnImage->load(":/image/setting/about.jpg");
    m_aboutBgHkImage->load(":/image/setting/about_f.jpg");
    m_aboutBgEnImage->load(":/image/setting/about_en.jpg");
}

void Recource::SetSel()
{
    if(m_ilevelScore_2 != -1)
        m_selscene->m_level2Item->setVisible(true);
    if(m_ilevelScore_3 != -1)
        m_selscene->m_level3Item->setVisible(true);
    m_mainwindow->setScene(m_selscene);
}

void Recource::SetGame()
{
    Recource::m_gamesound->stop(0);
    Recource::m_gamesound->stop(1);
    if(Recource::m_bPlaySound)
    {
        Recource::m_gamesound->playBgSound(1);
    }

    m_mainwindow->setScene(m_gamescene);
    m_gamescene->setWidgetParent(m_mainwindow);
}

void Recource::LoadData()
{
    QSettings settings("MySoft", "Score");
    m_ilevelScore_1 = settings.value("Score/level_1",-1).toInt();
    m_ilevelScore_2 = settings.value("Score/level_2",-1).toInt();
    m_ilevelScore_3 = settings.value("Score/level_3",-1).toInt();

//    m_ilevelScore_1 = -1;
//    m_ilevelScore_2 = -1;
//    m_ilevelScore_3 = -1;

//    SaveData();

    m_bPlaySound = settings.value("main/sound",false).toBool();
}

void Recource::SaveData()
{
    QSettings settings("MySoft", "Score");
    settings.setValue("Score/level_1",m_ilevelScore_1);
    settings.setValue("Score/level_2",m_ilevelScore_2);
    settings.setValue("Score/level_3",m_ilevelScore_3);

    settings.setValue("main/sound",m_bPlaySound);
}
